﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace JKF.DataModule.SqlServerDAL
{
   public partial class dalSTOCK_AMOUNT:IDAL.IdalSTOCK_AMOUNT
    {// SORT_NAME, NAME, MODEL, PRODUCT_NUMS, PRODUCT_KEY, SHOP_CODE
       private const string FieldShow = "SORT_NAME, NAME, MODEL, PRODUCT_NUMS, PRODUCT_KEY, SHOP_CODE";
       private const string FieldOrder = "NAME,MODEL,PRODUCT_NUMS";
       private const string FieldKey = "PRODUCT_KEY, SHOP_CODE";
       /// <summary>
       ///  从视图 dbo.V_PRODUCT_STOCK_Amount 获取库存数据列表
       /// </summary>
       /// <param name="shop_code">当前用户所属店面</param>
       /// <param name="product_key">产品名称</param>
       /// <param name="product_model">产品型号/规格</param> 
       /// <param name="ownShop">所属店铺</param> 
       /// <param name="pageCurrent">当前页码</param>
       /// <param name="pageSize">一页显示多少条数据</param>
       /// <param name="pageCount">总页数</param>
       /// <param name="rowCount">总记录数</param>
       /// <returns>返回DataTable数据集</returns>
       public static DataTable GetStock_AmountsDAL(string shop_code, string product_key, string product_model, string ownShop, int pageCurrent, int pageSize, ref int pageCount, ref int rowCount)
        {
            //获取有效的入库记录 1.表示有效，9表示删除
            var sql = new StringBuilder(string.Format("  shop_code='{0}'  ", shop_code));
            //if (!string.IsNullOrEmpty(NAME))
            //{
            //    sql.AppendFormat(" AND NAME  LIKE '%{0}%'", NAME);
            //}
            if (!string.IsNullOrEmpty(product_model))
            {
                sql.AppendFormat(" AND MODEL= '{0}'", product_model);
            }
            if (!string.IsNullOrEmpty(product_key))
            {
                sql.AppendFormat(@" AND PRODUCT_KEY IN (select [value] 
from [dbo].[Split_Product_Key]('{0}',','))", product_key);
            }
            if (!string.IsNullOrEmpty(ownShop))
            {
                sql.AppendFormat(" and Shop_code in('{0}')", string.Join("','", ownShop.Split(',')));
            }

            return DataPage.GetPageInfo("dbo.V_PRODUCT_STOCK_AMOUNT", FieldKey, pageCurrent, pageSize, FieldShow, FieldOrder, sql.ToString(), ref pageCount, ref rowCount).Tables[0];
        }
    }
}
